<template>
  <div class="container">
  <el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button>

<el-dialog
  title="修改"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
        <el-form :model="ruleForm" status-icon  ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="报名费" prop="pass">
            <el-input type="text" v-model="ruleForm.pay" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="销量" prop="checkPass">
            <el-input type="text" v-model="ruleForm.num" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="上传人" prop="name">
            <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item>
            <!-- <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button> -->
      
        </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="closeParent">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        </span>
        </el-dialog>
  </div>
</template>

<script>
 import {updateHomeApi} from '../../../api/homeApi.js'

export default {
    props: ['arr'],
data() {
   
      return {
        dialogVisible: true  ,  //让其永远显示
        ruleForm:{
          pay:'',
          num:'',
          name:''
        },
        
      };
    },
    mounted () {
      this.ruleForm  = JSON.parse(JSON.stringify(this.arr))
    },
     methods: {
        //  提交按钮
        submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // alert('submit!');
            // console.log(ruleForm)
            // 添加第二步,数据准备好之后,提交数据 ,后端把数据添加数组,通知前端
            updateHomeApi(this.ruleForm).then(res=>{
                    console.log(res) 
                    this.$parent.isshow= false
                    this.$emit('resetfun')
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    //   弹窗的
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
            this.$parent.isshow=false
          })
          .catch(_ => {});
      },
      closeParent(){
          this.$parent.isshow=false
      }
    }
}
</script>

<style>
    
</style>